package cn.kgc.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author: fighting
 * @date: 2022/2/4
 * @description:
 */
//看官网
@Component
@Slf4j
public class MyMetaObjectHandler implements MetaObjectHandler {
    //自动生成的方法与实体类的TableType一致


    //插入时的填充策略
    @Override
    public void insertFill(MetaObject metaObject) {
        log.info("start insert fill.......");
        //setFieldValByName(String fieldName 字段名, Object fieldVal字段值, MetaObject metaObject那个数据处理)
        this.setFieldValByName("createTime",new Date(),metaObject);
        this.setFieldValByName("updateTime",new Date(),metaObject);

    }
    //修改时的填充策略
    @Override
    public void updateFill(MetaObject metaObject) {
        log.info("start update fill.......");
        this.setFieldValByName("updateTime",new Date(),metaObject);
    }
}
